{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <form class="layui-form gg-form-bar border-x border-t" lay-filter="barsearchform2">
        <div class="layui-input-inline layui-td-gray" style="width:300px;">
            <input id="year" name="year" autocomplete="off"  class="layui-input" value="{$date}"  lay-verify="required" placeholder="请选择月份" lay-reqText="请选择月份">
        </div>
        <div class="layui-input-inline">
            {if condition="$eid gt 0"}
            <input type="hidden" name="eid" value="{$eid}" lay-verify="required">
            {else/}
            <select name="eid" lay-filter="status">
                <option value="0">系统管理员</option>
                {volist name="enterprise" id="v"}
                <option value="{$v.id}" >{$v.title}</option>
                {/volist}
            </select>
            {/if}
        </div>
        <div class="layui-input-inline" style="width:150px;">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
        </div>
    </form>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <span class="layui-btn layui-btn-sm" title="添加固定资产工时" lay-event="add">+ 添加固定资产工时</span>
  </div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
	<script>
	const moduleInit = ['tool'];

    //表头工具栏事件

	function gouguInit() {
		var table = layui.table, tool = layui.tool, form = layui.form;

        table.on('toolbar(test)', function(obj){

            var data = form.val('barsearchform2');
            if (obj.event === 'add') {
                tool.side(`/home/EquipmentWorkHours/operation?year=${data.year}&eid=${data.eid}`);
                return;
            }
        });

		layui.pageTable = table.render({
			elem: '#test'
			,toolbar: '#toolbarDemo'
			,defaultToolbar: false
			,title:'固定资产工时'
			,url: "/home/EquipmentWorkHours/index"
			,cols: [[
					{field:'id',width:80, title: 'ID号', align:'center'}
					,{field:'month',title: '月份'}
					,{field:'all_time',title: '合作项目工时(小时)'}
					,{width:150,title: '操作', align:'center',templet: function(d){
						var html='';
                        var btn='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="look">查看</a>';
                        html = '<div class="layui-btn-group">'+btn+'<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>'+'</div>';
						return html;
					}}
				]]
			});

        table.on('tool(test)',function (obj) {
            if(obj.event === 'look'){
                tool.side('/home/EquipmentWorkHours/getEquHours?year='+obj.data.year+"&month="+obj.data.month+"&eid="+ obj.data.eid);
                return;
            }
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗？', { icon: 3, title: '提示' }, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            layui.pageTable.reload();
                        }
                    }
                    tool.post("/home/EquipmentWorkHours/delete", { eid: obj.data.eid,year:obj.data.year,month:obj.data.month }, callback);
                    layer.close(index);
                });
            }
        });


        //监听搜索提交
        form.on('submit(webform)', function (data) {
            layui.pageTable.reload({ where: data.field });
            return false;
        });

        var form = layui.form,
            tool=layui.tool,
            oaTool=layui.oaTool,
            laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#year',
            type: 'year',
            format: 'yyyy',
            showBottom: false
        });



		}
	</script>
{/block}
<!-- /脚本 -->